package com.settlement.system.service.impl;

import com.settlement.system.model.dto.AuthorityUserModuleDto;
import com.settlement.system.model.entity.common.AuthorityRole;
import com.settlement.system.model.entity.common.AuthorityUser;
import com.settlement.system.model.entity.common.AuthorityUserRegion;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * UC接口
 *
 * @author hsiang
 * @version 0.1.0
 * @date 2019年3月20日 下午2:20:49
 */
@Service
@Slf4j
public class AuthorityUserService {

    @Value("${authority.system-id}")
    private int systemId;

	/*@Reference(version = "${dubbo.uc.api.version}")
	private AuthorityUserDataApi authorityUserDataApi;

	@Reference(version = "${dubbo.uc.api.version}")
	private AuthorityUserApi authorityUserApi;*/

    /**
     * 查询用户所拥有的全部模块信息
     *
     * @param userId
     * @return
     */
    public List<AuthorityUserModuleDto> findAllUserHasModules(Integer userId) {
        List<AuthorityUserModuleDto> authorityUserModuleDtos = null;
        try {
            /*authorityUserModuleDtos = authorityUserApi.findAllUserHasModules(userId, Integer.valueOf(systemId));*/
        } catch (NumberFormatException e) {
            log.error("uc查询用户所拥有的全部模块信息异常", e);
        }
        return authorityUserModuleDtos;
    }

    /**
     * 根据userId获取用户大区权限
     *
     * @param userId
     * @return
     */
    public List<AuthorityUserRegion> userRegion(Integer userId) {
        userId = userId == null ? -1 : userId;
        // 用户大区权限
        List<AuthorityUserRegion> authorityUserRegions = null;
        try {
            /*authorityUserRegions = authorityUserDataApi.userRegion(userId);*/
        } catch (Exception e) {
            log.error("uc根据id用户大区权限异常", e);
        }
        return authorityUserRegions;
    }

    /**
     * 根据id查找用户
     *
     * @param userId
     * @throws RpcException
     */
    public AuthorityUser findAuthorityUserById(Integer userId) {
        userId = userId == null ? 0 : userId;
        AuthorityUser authorityUser = null;
        try {
            /*authorityUser = authorityUserApi.findAuthorityUserById(userId);*/
        } catch (Exception e) {
            log.error("uc根据id查找用户异常", e);
        }
        return authorityUser;
    }

    /**
     * 根据用户工号查询用户
     *
     * @return
     * @throws RpcException
     */
    public AuthorityUser findAuthorityUserByUserNo(String userNo) {
        userNo = userNo == null ? "" : userNo;
        AuthorityUser authorityUser = null;
        try {
            /*authorityUser = authorityUserApi.findAuthorityUserByUserNo(userNo);*/
        } catch (Exception e) {
            log.error("uc根据用户工号查询用户异常", e);
        }
        return authorityUser;
    }

    /**
     * 获取用户角色列表,传0获取全部
     *
     * @return
     * @throws RpcException
     */
    public List<AuthorityRole> findUserRoles(Integer userId) {
        userId = userId == null ? 0 : userId;
        List<AuthorityRole> data = null;
        try {
            /*data = authorityUserApi.findUserRoles(userId);*/
        } catch (Exception e) {
            log.error("uc获取用户角色列表异常", e);
        }
        return data;
    }

}
